package hn.cch.demo.spi;

import org.junit.jupiter.api.Test;
import org.springframework.core.io.support.SpringFactoriesLoader;

import java.util.List;
import java.util.ServiceLoader;

public class ServiceProviderInterfaceTest {


    @Test
    public void testJavaSpi() {
        ServiceLoader<ServiceProviderInterface> serviceLoader = ServiceLoader.load(ServiceProviderInterface.class);
        serviceLoader.forEach(service -> {
            service.call();
            System.out.println(service.getClass().getName());
        });
    }

    @Test
    public void testSpringSpi() {
        List<ServiceProviderInterface> list = SpringFactoriesLoader.loadFactories(ServiceProviderInterface.class,
                Thread.currentThread().getContextClassLoader());
        list.forEach(service -> {
            service.call();
            System.out.println(service.getClass().getName());
        });
    }

}
